#include <unordered_map>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

class Solution {
public:
    vector<vector<string>> groupAnagrams(vector<string>& strs) {
        unordered_map<string, vector<string>> ht;
        for (auto& s : strs) {
            string key = s;
            sort(key.begin(), key.end());
            ht[key].emplace_back(s);
        }
        vector<vector<string>> ret;
        for (auto& e : ht) {
            ret.emplace_back(e.second);
        }
        return ret;
    }
};